<template>
  <dialog-editor ref="dialog"></dialog-editor>
</template>

<script>
import DialogEditor from '@/components/DialogEditor'
import dialogMixins from '@/utils/commonDialogMixins'
import {mRequest} from '@/utils/request'
export default {
  mixins: [dialogMixins],
  components: {DialogEditor},
  data() {
    return {
      dataFormConfig: {
        id: {
          hidden: true
        },
        proofingName: {
          label: '打样名称',
          placeholder: '请输入打样名称'
        },
        modelId: {
          label: '模具',
          type: 'list',
          placeholder: '请选择模具',
          isNeedAdd: true,
          addNewItemFunc: this.addNewModelInfo,
          selectCallback: this.modelIdSelectCallback,
          list: []
        },
        privateModel: {
          label: '公/私模',
          type: 'radio',
          radioBorder: false,
          radioList: [
            {text: '公模', label: 0},
            {text: '私模', label: 1}
          ],
          default: 0
        },
        clientId: {
          hidden: true,
          label: '客户',
          type: 'list',
          list: [],
          filterable: true,
          placeholder: '请输入客户名',
          isNeedAdd: true,
          addNewItemFunc: this.addNewClientInfo
        },
        chargeStatus: {
          label: '收费情况',
          type: 'radio',
          radioBorder: false,
          radioList: [
            {text: '免费', label: 0},
            {text: '收费', label: 1}
          ],
          default: 0
        },
        unitPrice:{
          label: '打样价格',
          type: 'number',
          max: 10000000,
          reply: () => this.R.equals(1, this.dataForm['chargeStatus'])
        },
        number: {
          label: '数量',
          type: 'number',
          max: 1000,
          default: 0
        },
        calibrator: {
          label: '口径'
        },
        weight: {
          label: '克数',
          type: 'number',
          max: 1000,
          default: 0
        },
        weightScope:{
          label: '克重误差范围(±)',
          type: 'String',
          default: '±'
        },
        volume: {
          label: '容量',
          type: 'number',
          max: 1000,
          default: 0
        },
        volumeScope:{
          label: '容量误差范围(±)',
          type: 'String',
          default: '±'
        },
        proofingTime: {
          label: '打样时间',
          type: 'date',
          placeholder: '请选择打样时间'
        },

        customerProductStyle: {
          label: '客户样品',
          type: 'switch',
          activeValue: 1,
          inactiveValue: 0,
          default: 0
        },

        bottleLength: {
          label: '瓶长(mm)',
          type: 'number',
          max: 1000,
          default: undefined
        },
        bottleWeight: {
          label: '瓶宽(mm)',
          type: 'number',
          max: 1000,
          default: undefined
        },
        bottleHeight: {
          label: '瓶高(mm)',
          type: 'number',
          max: 1000,
          default: undefined
        },
        bottleCapSuit: {
          label: '瓶盖套装',
          type: 'switch',
          activeValue: 1,
          inactiveValue: 0,
          default: 0
        },
        modelProofingStatus: {
          label: '试样模是否到位',
          type: 'radio',
          radioBorder: false,
          radioList: [
            {text: '未到位', label: 0},
            {text: '已到位', label: 1}
          ],
          default: 1
        },
        productDrawingId: {
          label: '样品图纸',
          type: 'uploadImage',
          imageType: 'uploadProductPaper'
        },
        bottleCraft:{
          label: '工艺',
          inputType: 'textarea'
        },
        remark: {
          label: '备注'
        },
        // productIsNew: {
        //   label: '是否新产品',
        //   type: 'radio',
        //   radioBorder: false,
        //   reply: () => this.dataForm.id,
        //   radioList: [
        //     {text: '不是新产品', label: 0},
        //     {text: '是新产品', label: 1}
        //   ],
        //   default: 1
        // },
        realWeight: {
          label: '实测重量',
          type: 'number',
          max: 1000,
          reply: () => this.dataForm.id,
          default: 0
        },
        realVolume: {
          label: '实测容量',
          type: 'number',
          reply: () => this.dataForm.id,
          max: 1000,
          default: 0
        },
        captainIssue: {
          label: '客户反馈',
          reply: () => this.dataForm.id,
        },
        clientIssue: {
          label: '客户问题',
          reply: () => this.dataForm.id,
        },
        qAIssue: {
          label: '质检反馈',
          reply: () => this.dataForm.id
        },
        saleIssue: {
          label: '销售反馈',
          reply: () => this.dataForm.id,
        },
        location:{
          label: '存放位置',
          type: 'String',
          default: '',
          reply: () => this.dataForm.id,
        },
        expressWaybillNo:{
          label: '快递单号',
          type: 'String',
          default: '',
          reply: () => this.dataForm.id,

        },

        proofingImage: {
          label: '样品图片',
          type: 'uploadImage',
          imageType: 'uploadProductPaper',
          reply: () => this.dataForm.id,
        },
        proofingFeedback: {
          label: '样品反馈单',
          type: 'uploadImage',
          imageType: 'uploadProductPaper',
          reply: () => this.dataForm.id,
        },
        status: {
          label: '订单状态',
          type: 'radio',
          radioBorder: false,
          radioList: [
            {text: '加急', label: 2},
            {text: '正常', label: 3},
            {text: '完成', label: 5},
            {text: '待确认', label: 90}
          ],
          default: 3
        }
      }
    }
  },
  methods: {
    init(id) {
      this.dataForm.id = id || 0
      this.initModelInfoList('modelId')
      this.initClientInfoList()
      this.initProductDeviceListByParent('deviceId')

      this.$refs.dialog.initDialog({
        dataForm: this.dataForm,
        config: this.dataFormConfig,
        dataRule: this.getNeedDataRule('proofingName','unitPrice', 'number','calibrator','clientId', 'weight','bottleLength','bottleWeight','bottleHeight', 'proofingTime', 'localProduct', 'productDrawingId','status'),
        initApi: 'orderApi/orderProofingInfo',
        saveApi: 'orderApi/saveOrderProofing',
        updateApi: 'orderApi/updateOrderProofing',
        objectName: 'orderProofing'
      })
    },
    addNewClientInfo(){
      const cb = (newValue) => {
        this.initClientInfoList()
        this.dataForm.clientId = newValue.id
      }
      this.$parent.openClientInfoDialog(cb)
    },
    addNewModelInfo(){
      const cb = (newValue) => {
        this.initModelInfoList()
        this.dataForm.modelId = newValue.id
      }
      this.$parent.openModelInfoDialog(cb)
    },
    modelIdSelectCallback() {

      mRequest('orderApi/getOrderProofingByModelId', {modelId: this.dataForm.modelId}, (res) => {
        const {data} = res
        const {orderProofing} = data
        const {bottleLength,bottleWeight,bottleHeight} = orderProofing
        this.dataForm.bottleLength = bottleLength
        this.dataForm.bottleWeight = bottleWeight
        this.dataForm.bottleHeight = bottleHeight
      })
    },
  }
}
</script>
